#include "StdAfx.h"
#include "TechBase.h"


CTechBase::CTechBase(void)
	: m_pKData(NULL)
	, m_fpTech(NULL)
	, m_nCurDayIdx(-1)
{
	memset(m_StackIdx, 0, sizeof(m_StackIdx));
}


CTechBase::~CTechBase(void)
{
}


int CTechBase::CalcTech(void)
{
	return 0;
}


int CTechBase::Push(int Idx, double val)
{
	if (Idx < 0 || Idx >= STACK_COUNT)
	{
		return -1;
	}
	m_Stacks[Idx][m_StackIdx[Idx]%STACK_LEN] = val;
	m_StackIdx[Idx]++;

	return 0;
}


int CTechBase::GetVal(int Idx, int refIdx, double &Val)
{
	if (Idx < 0 || Idx >= STACK_COUNT)
	{
		return -1;
	}
	int sIdx = m_StackIdx[Idx] - refIdx - 1;
	if ( sIdx < 0 || refIdx>= STACK_LEN )
	{
		return -2;
	}

	Val = m_Stacks[Idx][sIdx%STACK_LEN];
	return 0;
}
